Repository navigation
fix: show maintenance message when LNbits is down - #76
Conversation
There was a problem hiding this comment.
If your organization's extra usage balance is empty, an organization admin can add extra usage credits at claude.ai/admin-settings/usage. If its monthly spend limit was reached, an admin can raise it on the same page. If neither applies, contact Anthropic support.
Once extra usage is available, someone with write access to this repository can comment @claude review on this pull request to trigger a review.
When LNbits stopped responding, /balance showed a 0 balance and other commands hung for up to 2 minutes before failing with mixed errors. - Track LNbits health on every request: connection errors, timeouts and 502/503/504 mark it down; any other answer marks it up. A background probe checks /api/v1/health every 15s so the bot recovers on its own. - Gate LNbits-dependent Telegram handlers: while down they reply at once with a maintenance message (callback alert / inline result as fitting; silent for non-command group messages). Help, convert and cancel buttons keep working. - /balance never shows a made-up 0: it shows the maintenance message plus the last known balance, or "try again later" for other errors. - Cut the LNbits request timeout from 2 minutes to 15s. Payments keep their 24h timeout.
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
Sends a message to the log group when LNbits has been unreachable for 30s, and a recovery message with the downtime once it answers again. The delay keeps a single failed request from paging anyone; short outages send no alerts at all.
Problem
When LNbits stops responding:
/balanceshows 0 sats, so users think their funds are gone.Other commands hang for up to 2 minutes (the default
reqtimeout), then fail with mixed errors, or with no reply at all (inline send).Fix
Health tracking (
internal/lnbits/health.go): every LNbits request goes through a transport that records the outcome. Connection errors, timeouts and 502/503/504 mark LNbits as down. Any other answer (including 4xx/500) marks it up. A background probe calls/api/v1/healthevery 15s, so the bot recovers on its own.Telegram gate (
internal/telegram/maintenance.go): handlers that need LNbits now stop early while it is down and reply at once:Buttons get an alert, and inline queries get an error result. In groups, only commands get a reply, so normal chat doesn't trigger spam. Help, convert/price and cancel buttons still work.
/balancenever shows a made-up 0. While down, it shows the maintenance message plus the last known balance from the DB. Other errors show "try again later".Timeouts: LNbits calls now time out after 15s instead of 2 min. Payments keep their 24h timeout.
Admin alert (
internal/telegram/lnbits_alert.go): if LNbits stays down for 30s, the log group gets "🔴 LNbits is down" with the error. When it comes back, the log group gets "🟢 LNbits is back up" with the downtime. Short glitches send nothing. It uses the existinglog_group_id/ error thread, so there are no new config settings.Not in this PR (follow-ups)
Manual maintenance switch for planned downtime
"Payment status unknown" wording for payments interrupted by an outage
API returns 503 instead of
balance: 0Testing
New tests in
internal/lnbits/health_test.gocover status handling, connection errors, probe recovery, a zero-value client and change events.lnbits_alert_test.gocovers the 30s alert delay. All pass.go build ./...passes.internal/telegramhas 5 failing tests (referral, tooltip). They fail the same way onmain.